package net.zjitc.servlet;

import net.zjitc.service.ProductService;
import net.zjitc.service.impl.ProductServiceImpl;
import net.zjitc.utils.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by hasee on 2017/10/27.
 */
@WebServlet(name = "ProductListServlet",urlPatterns = "/productListServlet")
public class ProductListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        String num = request.getParameter("pageNum");
        String condition = request.getParameter("condition");
        if(num==null||"".equals(num)){num = "1";}
        if(condition==null){condition="";}

        int pageNum = Integer.valueOf(num);

        ProductService service  = new ProductServiceImpl();
        PageBean pageBean = new PageBean();
        pageBean=service.findPage(pageNum,condition);

        request.setAttribute("pageBean",pageBean);
        request.getRequestDispatcher("/product/productlist.jsp").forward(request,response);
    }
}
